//
//  ViewController.m
//  06-UINavigationController
//
//  Created by 曹曹 on 16/7/21.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置navigationBar的属性
    // 1.title标题, 告诉用户这个视图的作用
    // self.title = @"呵呵呵呵";
    self.navigationItem.title = @"哈哈哈哈";
    // 2.titleView标题视图
    // 标题视图修改x 和 y 对本身视图没有影响(居中)
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"nihao", @"buhao", @"haha"]];
    segment.frame = CGRectMake(0, 0, 150, 20);
    self.navigationItem.titleView = segment;
    // 3.leftBarButtonItem
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"<返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    // 4.rightBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    // 5.leftBarButtonItems(可以添加多个, 会使titleView的位置向右移动)
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"<返回" style:UIBarButtonItemStylePlain target:self action:@selector(comeBack:)];
    UIBarButtonItem *barButtonItemImage = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    self.navigationItem.leftBarButtonItems = @[barButtonItem, barButtonItem, barButtonItem, barButtonItemImage, barButtonItemImage];
    // 6.rightBarButtonItems 数组
    // barButtonItems数组中放1 ~ 2个item为最优
    // 7.隐藏navigationBar, YES隐藏, 默认为NO
    // self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBar.hidden = NO;
    // 8.navigationBar背景样式, 默认UIBarStyleDefault
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    // 9.navigationBar背景颜色(不推荐使用)
    // self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    // 10.barTintColor背景颜色,bar的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    // 11.tintColor Bar上面所有元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 12.translucent管理半透明效果 YES为开启, NO为关闭
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blackColor];
    button.frame = CGRectMake(0, 0, 200, 200);
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    // iOS 7以后 默认为YES, iOS 6以及以前都是NO
    // 设置为YES时, self.view的坐标系从原点开始
    // 设置为NO时, self.view的坐标系从NavigationBar下面开始
    self.navigationController.navigationBar.translucent = YES;
    // 13.改变坐标系效果, 与translucent为NO时效果一样
    self.edgesForExtendedLayout = UIRectEdgeNone;
#pragma mark - 页面跳转
    // 1.入栈pushViewController
    // 2.出栈popViewControllerAnimated
    // 3.ViewControllers 存放navigationController里所有的视图控制器
    // 4.topViewController栈顶视图控制器
    // 5.visibleViewController可见视图控制器(当前显示的)
    // self.navigationController.topViewController;
    
}

- (void)comeBack:(UIBarButtonItem *)barButtonItem {
    NSLog(@"返回");
}

- (void)add:(UIBarButtonItem *)barButtonItem {
    NSLog(@"add");
}

- (void)buttonClicked:(UIButton *)button {
    // 视图控制器入栈, 返回上一级
    [self.navigationController pushViewController:[[PushViewController alloc] init] animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
